<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/10/22
 * Time: 19:39
 */
namespace Api\Model;
use Think\Model;

class GoodsInfoModel extends Model{


    //获取某个分类的子分类
    public function getChildren($data,$class_id){
        //对获取的信息进去格式化
        $list=$this->getTree($data,$class_id);//为false，查询单一数据,清除缓存
        foreach ($list as $key=>$value){
//            $tree[]=$value['class_id'];
            $tree[]=$value['name'];
        }
        return $tree;
    }
	//格式化分类信息  无限极分类
	public function getTree($data,$class_id=0){//为true查询所有数据
        static $list = array();

        foreach($data as $key=>$value){
            if($value['parent_class_id']==$class_id){
                $list[]=$value;

                //使用递归方法获取分类下的子分类
                $this->getTree($data,$value['class_id']);
            }
        }
        return $list;
        //dump($list);die;
    }

}